package com.sky.backend.system.service.impl;

import com.sky.backend.system.dao.SystemMenuMapper;
import com.sky.backend.pojo.MenuVo;
import com.sky.backend.system.entity.SystemMenu;
import com.sky.backend.utils.TreeUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SystemMenuServiceImpl {
    @Autowired
    protected SystemMenuMapper systemMenuMapper;

    public int insert(SystemMenu entity) {
        return systemMenuMapper.insert(entity);
    }

    public int deleteByPrimaryKey(Integer id) {
        return systemMenuMapper.deleteByPrimaryKey(id);
    }

    public int updateByPrimaryKey(SystemMenu record) {
        return systemMenuMapper.updateByPrimaryKey(record);
    }

    public List<SystemMenu> selectAll() {
        return systemMenuMapper.selectAll();
    }

    public Map<String, Object> menu() {
        Map<String, Object> map = new HashMap<>(16);
        Map<String,Object> home = new HashMap<>(16);
        Map<String,Object> logo = new HashMap<>(16);
        List<SystemMenu> menuList = systemMenuMapper.selectAll();
        List<MenuVo> menuInfo = new ArrayList<>();
        for (SystemMenu e : menuList) {
            MenuVo menuVO = new MenuVo();
            menuVO.setId(e.getId());
            menuVO.setPid(e.getPid());
            menuVO.setHref(e.getHref());
            menuVO.setTitle(e.getTitle());
            menuVO.setIcon(e.getIcon());
            menuVO.setTarget(e.getTarget());
            menuInfo.add(menuVO);
        }
        map.put("menuInfo", TreeUtil.toTree(menuInfo, 0));
        home.put("title","首页");
        home.put("href","page/welcome-1.html?t=1");//控制器路由,自行定义
        logo.put("title","RUGE ADMIN");
        logo.put("image","images/logo.png");//静态资源文件路径,可使用默认的logo.png
        map.put("homeInfo", home);
        map.put("logoInfo", logo);
        return map;
    }
}